<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>cims</title>

</head>
<body>
    <script src="./jquery.min.js"></script>
    <script src="./sm2.js"></script>
    <script>

        let publicKey = 'af0ea01e61236c863009b4174d1ec550de327db602ae49a29ebaa4c2583e6443bac6735f06888d4516484d5bfc575ee7f5e8b6dd7f5bdc0d172b2568148a2f2e'
        let keypair = sm2.generateKeyPairHex()
        console.log(keypair)

        console.log(sm2.doEncrypt('测试', publicKey, 0)) // 加密结果

        var token = null

        // 未授权之前
        $.ajax({
            url: 'http://localhost:9527/cims/rest/leave/list?pageNum=1&pageSize=10&sortOrder=start_time+desc',
            contentType: 'application/json',
            type: 'GET',
            async: false,
            crossDomain: true,
            dataType: 'json',
            success(data, status, xhr) {
                console.log(data)
                console.log(status)
            }
        })

        // 授权
        $.ajax({
            url: 'http://localhost:9527/cims/app/authentication?j_username=admin&j_password=test',
            contentType: 'application/json',
            type: 'POST',
            async: false,
            crossDomain: true,
            dataType: 'json',
            success(data, status, xhr) {
                console.log(data)
                token = data.token
                // token = xhr.getResponseHeader('token')
                console.log(token)
                console.log(status)
                console.log(xhr.getAllResponseHeaders())
            }
        })

        document.cookie = token

        // 授权之后
        $.ajax({
            url: 'http://localhost:9527/cims/rest/leave/list?pageNum=1&pageSize=10&sortOrder=start_time+desc',
            contentType: 'application/json',
            type: 'GET',
            async: false,
            crossDomain: true,
            dataType: 'json',
            // headers: {
            //     "cookie": token,
            //     "token": token
            // },
            // xhrFields: {
            //     withCredentials: true
            // },
            success(data, status, xhr) {
                console.log(data)
                console.log(status)
            }
        })

    </script>
</body>
</html>